<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<link rel="icon" type="image/png" href="img/favicon.ico">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>指纹单元</title>
		<link rel="stylesheet" href="css/style.min.css" />
	</head>
	<body>
		<header id="header" class="header">
			<div class="logo">
				<img src="img/logo.png" alt="logo" style="height: 62px;">
			</div>
			<div class="nav">
				<ul class="header-list">
					<li>
						<a href="index.html">指纹库</a>
					</li>
					<li>
						<a class="active" href="#">系统设置</a>
					</li>
					<li>
						<a href="collect.html">指纹录入</a>
					</li>
				</ul>
			</div>
		</header>
		<div class="content">
			<fieldset>
				<legend>硬件信息</legend>
				<table cellpadding="0" cellspacing="0">
					<tbody>
						<tr>
							<td width="35%" align="right">固件版本：</td>
							<td style="padding: 0;">
								<input class="inputxt" type="text" value="1.0.0" disabled="disabled" />
							</td>
						</tr>
						<tr>
							<td width="35%" align="right">设备名称：</td>
							<td style="padding: 0;"><input class="inputxt" type="text" disabled="disabled" value="以太网指纹" /></td>
						</tr>
						<tr>
							<td width="35%" align="right">MAC地址：</td>
							<td style="padding: 0;">
								<input id="MAC" class="inputxt" type="text" disabled="disabled" value="" />
							</td>
						</tr>
					</tbody>
				</table>

				<legend>网络配置</legend>
				<table cellpadding="0" cellspacing="0">
					<tbody>
						<tr>
							<td colspan="2" style="text-align: center;">
								<input type="radio" name="settyp" value="1" checked/>Static IP&nbsp;&nbsp;
								<input type="radio" name="settyp" value="2"/>DHCP
							</td>
						</tr>
						<tr>
							<td width="35%" align="right">IP地址：</td>
							<td style="padding: 0;">
								<input id="IP" class="inputxt" type="text" value="" />
							</td>
						</tr>
						<tr>
							<td width="35%" align="right">网关地址：</td>
							<td style="padding: 0;">
								<input id="Gateway" class="inputxt" type="text" value="" />
							</td>
						</tr>
						<tr>
							<td width="35%" align="right">子网掩码：</td>
							<td style="padding: 0;">
								<input id="sub" class="inputxt" type="text" value="" />
							</td>
						</tr>
						<tr>
							<td width="35%" align="right">DNS：</td>
							<td style="padding: 0;">
								<input id="dns" class="inputxt" type="text" value="" />
							</td>
						</tr>
					</tbody>
				</table>
			</fieldset>
			<button id="rebootBt" type="button" class="btn btn-success btn-block" onclick="javascript:config('1');">保存并重启设备</button>			
		</div>
		<span id="wait" style="display: none;">please wait for a while, the module will boot in</span><span style='color:red;' id='delay'></span>
			<span id="wait1" style="display: none;">seconds.</span>
	</body>
		
	<script type="text/javascript" src="js/app.min.js"></script>
	<script type="application/javascript">
		window.onload = function() {
			ajax({
				url: 'configOL.cgi',
				method: 'POST',
				success: function(rsp) {
					var obj = JSON.parse(rsp);
					document.getElementById('MAC').value = obj.MAC;
					document.getElementById('IP').value = obj.IP;
					document.getElementById('Gateway').value = obj.Gateway;
					document.getElementById('sub').value = obj.sub;
					document.getElementById('dns').value = obj.dns;
				},
				error: function(rsp) {
					console.log(rsp);
				}
			});
		}
		function getRadioValue(radioName){
		    var radios = document.getElementsByName(radioName);
		    var value;
		    for(var i=0;i<radios.length;i++){
		        if(radios[i].checked){
		            value = radios[i].value;
		            break;
		        }
		    }
		    return value;
		}
		function config(IPconfig) {
			var IP = document.getElementById('IP').value;
			var Gateway = document.getElementById('Gateway').value;
			var sub = document.getElementById('sub').value;
			var dns = document.getElementById('dns').value;
			var dhcp = getRadioValue('settyp');
			ajax({
				url: 'config.cgi',
				data: {
					IP: IP,
					Gateway: Gateway,
					sub: sub,
					dns: dns,
					dhcp: dhcp
				},
				method: 'POST',
				success: function(rsp) {
					var obj = JSON.parse(rsp);
					if (obj.res == '1') {						
						document.getElementById('wait').style='';
						document.getElementById('wait1').style='';
						window.location.href = 'index.html';
						document.getElementById('wait').style='';
						document.getElementById('wait1').style='';
						var hm = 'http://192.168.10.225/';
						func(10);
					}
				},
				error: function(rsp) {
					console.log(rsp);
				}
			})
		}	
		function funDelay(s) {
			document.getElementById('delay').innerText = ' ' + s + ' ';
			s--;
			if(s != 0)
			{
				setTimeout('funDelay('+s+')', 1000);
			}
			else
			{
				window.location.href = 'http://192.168.10.225/';
			}
		}		
	</script>	
</html>